package com.fx.zmlzml.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fx.zmlzml.entity.PcCooler;
import com.fx.zmlzml.mapper.PcCoolerMapper;
import com.fx.zmlzml.service.PcCoolerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 电脑散热器 Service实现类
 * 实现电脑散热器相关的业务逻辑
 */
@Service
public class PcCoolerServiceImpl extends ServiceImpl<PcCoolerMapper, PcCooler> implements PcCoolerService {
    
    private static final Logger logger = LoggerFactory.getLogger(PcCoolerServiceImpl.class);

    @Override
    public List<PcCooler> getListByParams(Integer maxPrice, Integer minPrice) {
        logger.info("查询所有符合条件的电脑散热器列表，查询条件：maxPrice={}, minPrice={}", maxPrice, minPrice);
        List<PcCooler> list = baseMapper.getListByParams(maxPrice, minPrice);
        logger.info("散热器总条数：{}", list.size());
        return list;
    }

    @Override
    public boolean save(PcCooler entity) {
        logger.info("保存电脑散热器信息，制造商：{}", entity.getManufacturer());
        try {
            boolean result = super.save(entity);
            if (result) {
                logger.debug("保存电脑散热器成功，ID：{}", entity.getId());
            } else {
                logger.warn("保存电脑散热器失败，制造商：{}", entity.getManufacturer());
            }
            return result;
        } catch (Exception e) {
            logger.error("保存电脑散热器异常，制造商：{}", entity.getManufacturer(), e);
            throw e;
        }
    }
    
    @Override
    public boolean updateById(PcCooler entity) {
        logger.info("更新电脑散热器信息，ID：{}", entity.getId());
        try {
            boolean result = super.updateById(entity);
            if (result) {
                logger.debug("更新电脑散热器成功，ID：{}", entity.getId());
            } else {
                logger.warn("更新电脑散热器失败，ID：{}", entity.getId());
            }
            return result;
        } catch (Exception e) {
            logger.error("更新电脑散热器异常，ID：{}", entity.getId(), e);
            throw e;
        }
    }
    
    @Override
    public boolean removeById(Serializable id) {
        logger.info("删除电脑散热器信息，ID：{}", id);
        try {
            boolean result = super.removeById(id);
            if (result) {
                logger.debug("删除电脑散热器成功，ID：{}", id);
            } else {
                logger.warn("删除电脑散热器失败，ID：{}", id);
            }
            return result;
        } catch (Exception e) {
            logger.error("删除电脑散热器异常，ID：{}", id, e);
            throw e;
        }
    }
    
    @Override
    public PcCooler getById(Serializable id) {
        logger.info("查询电脑散热器信息，ID：{}", id);
        try {
            PcCooler cooler = super.getById(id);
            if (cooler == null) {
                logger.warn("未找到ID为{}的电脑散热器", id);
            } else {
                logger.debug("查询电脑散热器成功，ID：{}", id);
            }
            return cooler;
        } catch (Exception e) {
            logger.error("查询电脑散热器异常，ID：{}", id, e);
            throw e;
        }
    }
    
}